package com.jeeplus.test.jlnu.graduationInfo.controller;

import com.jeeplus.test.jlnu.graduationInfo.domain.vo.NewGraduationInfoReqVo;
import com.jeeplus.test.jlnu.graduationInfo.service.GraduationInfoFileService;
import com.jeeplus.test.tools.resp.R;
import io.minio.errors.MinioException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

@Api(tags = "毕业信息操作接口")
@RestController
@Slf4j
@RequestMapping("/graduationOperate")
public class GraduationOperateController {

    @Autowired
    GraduationInfoFileService graduationInfoFileService;

    @ApiOperation("挂接文档")
    @PostMapping("/hooking")
    //接收最多10个文件
    public R hooking(@RequestParam("file") MultipartFile[] files, HttpServletRequest request) {
        if (graduationInfoFileService.hooking(files,request)>0){
            return R.suc("挂接成功");
        }else {
            return R.error();
        }
    }

    @ApiOperation("审批文档")
    @GetMapping("/approve")
    //接收最多10个文件
    public R approve(@RequestParam("file") List<Long> ids,  HttpServletRequest request) throws MinioException, IOException, NoSuchAlgorithmException, InvalidKeyException {

            graduationInfoFileService.approve(ids);

        return R.suc("审批成功");
    }
    @ApiOperation("驳回文档")
    @GetMapping("/reject")
    //接收最多10个文件
    public R reject(@RequestParam("file") List<NewGraduationInfoReqVo> newGraduationInfoReqVo,  HttpServletRequest request) throws MinioException, IOException, NoSuchAlgorithmException, InvalidKeyException {

        graduationInfoFileService.reject(newGraduationInfoReqVo);

        return R.suc("驳回成功");
    }

}
